package crmdna.client.user;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import com.google.gson.Gson;
import com.googlecode.objectify.ObjectifyFilter;

public class UserCoreTest {
	
	private final LocalServiceTestHelper datastoreHelper =
	        new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()
	        	.setApplyAllHighRepJobPolicy());
	//local implementation / test harness implementation becomes HRD
	//only if setApplyAllHighRepJobPolicy is set. If the implementation is not HRD then
	//cross group transactions would fail (as master slave does not support it)
	          
	
    @Before
    public void setUp() {
        datastoreHelper.setUp();
        ObjectifyFilter.complete();                
    }

    @After
    public void tearDown() {       
    	ObjectifyFilter.complete();
        datastoreHelper.tearDown();
    }
    
    @Test public void getResourceFromPrivilegeTest() {
    	String[] split = "group||2||read".split("\\|\\|");
    	System.out.println("split: " + new Gson().toJson(split));
    	assertEquals(2, UserCore.getResourceFromPrivilege("GROUP||2||WRITE"));
    	assertEquals(2, UserCore.getResourceFromPrivilege("PROGRAM||2||WRITE"));		
	}        
}